<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/js/layui/css/layui.css" media="all">


</head>
<body>
<br>
<form class="layui-form" action="">
    <%--院校名称--%>
    <div class="layui-form-item">
        <label class="layui-form-label">院校名称<span style="color: red; font-size: larger"> *</span></label>
        <div class="layui-input-block">
            <input type="text" id="schName" style="width: 350px" name="username" value="" lay-verify="required" lay-reqtext="院校名称是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <%--院校账户名--%>
    <div class="layui-form-item">
        <label class="layui-form-label">院校账户名<span style="color: red; font-size: larger"> *</span></label>
        <div class="layui-input-block">
            <input type="text" id="schAccName" style="width: 350px" name="username" lay-verify="required" lay-reqtext="院校账户名是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <%--密码--%>
    <div class="layui-form-item">
        <label class="layui-form-label">密码<span style="color: red; font-size: larger"> *</span></label>
        <div class="layui-input-block">
            <input type="password" id="accPwd" lay-verify="required|pass" style="width: 350px" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <%--确认密码--%>
    <%--<div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">确认密码<span style="color: red; font-size: larger"> *</span></label>
            <div class="layui-input-inline">
                <input type="password" lay-verify="required|confirmPass" class="layui-input">
            </div>
        </div>
    </div>--%>
    <%--院校所在省份--%>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">院校所在省份<span style="color: red; font-size: larger"> *</span></label>
            <div class="layui-input-inline">
                <select name="modules" id="schProvince" lay-verify="required" lay-search="">
                    <option value="" class="a">请选择省</option>
                    <option value="江西省" class="province">江西省</option>
                    <option value="北京市" class="province">北京市</option>
                    <option value="上海市" class="province">上海市</option>
                    <option value="广东省" class="province">广东省</option>
                </select>
            </div>
        </div>
    </div>
    <%--院校详细地址--%>
    <div class="layui-form-item">
        <label class="layui-form-label">院校详细地址<span style="color: red; font-size: larger"> *</span></label>
        <div class="layui-input-block">
            <input type="text" id="schAddress" style="width: 350px" name="schAddress" lay-verify="required" lay-reqtext="院校详细地址是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <%--院校联络人--%>
    <div class="layui-form-item">
        <label class="layui-form-label">院校联络人<span style="color: red; font-size: larger"> *</span></label>
        <div class="layui-input-block">
            <input type="text" id="liaisons" style="width: 350px" name="liaisons" lay-verify="required" lay-reqtext="院校联络人是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <%--联络人手机号--%>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">联络人手机号<span style="color: red; font-size: larger"> *</span></label>
            <div class="layui-input-inline">
                <input type="tel" id="liaisonsTelephone" name="liaisonsTelephone" lay-verify="required|phone" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <%--表单提交--%>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="${pageContext.request.contextPath}/assets/js/core/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/layui/layui.js"></script>


<script>
    var schoolId = ${param.schoolId}; //获得 schoolManager.jsp页面传递过来的参数值

    var param = {
        schoolId:schoolId
    }
    var url = "/admin/selectSchoolBySchoolId";
    //回显院校信息
    $.get(url,param,function (data){
        $("#schName").val(data.school.schName);
        $("#schAccName").val(data.school.schAccName);
        $("#accPwd").val(data.school.accPwd);
        $("#schAddress").val(data.school.schAddress);
        $("#liaisons").val(data.school.liaisons);
        $("#liaisonsTelephone").val(data.school.liaisonsTelephone);
        var schProvince =  data.school.schProvince;
        //给下拉列表赋默认值
        var options = $(".province");
        if(options){
            var len = options.length;
            for(var i=0;i<len;i++){
                if(options[i].value == schProvince){
                    options[i].defaultSelected = true;
                    options[i].selected = true;
                    return true;
                }
            }
        }


    })

    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        form.render();

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义表单验证规则 （input输入框中的属性 lay-verify 的值与下面对应）
        // required 内置的校验 输入框内容不能为空
        //title 指标题验证，pass 指密码验证，可以自定义正则表达式，confirmPass 指两次密码相同验证
        form.verify({
            title: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            ,pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
            ,content: function(value){
                layedit.sync(editIndex);
            }
            ,confirmPass:function(value){
                if($('input[name=password]').val() !== value)
                    return '两次密码输入不一致！';
            }
        });

        //监听表单提交
        form.on('submit(demo1)', function(data){
            layer.confirm('确定提交吗？', function(index){ //弹出确定提交弹窗
                var param = {
                  schoolId:schoolId,
                  schName: $("#schName").val(),
                  schAccName: $("#schAccName").val(),
                  accPwd: $("#accPwd").val(),
                  schAddress: $("#schAddress").val(),
                  liaisons: $("#liaisons").val(),
                  liaisonsTelephone: $("#liaisonsTelephone").val(),
                  schProvince: $("#schProvince").val(),
                  _method: 'put'
                }
                /*发送修改请求*/
                var url = "/admin/updateSchoolBySchoolId";
                $.post(url,param,function (data){
                    if(data.code == 1001){      //修改成功跳转到 院校信息页面
                    //    layer.msg(data.msg);
                        layer.closeAll();       //关闭确认提交的弹出
                        layer.open({
                            type: 1
                            ,content: '<div style="padding: 20px 100px;">'+ data.msg +'</div>'
                            ,btn: '确定'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0 //不显示遮罩
                            ,yes: function(){
                            //    layer.closeAll();
                                top.location='schoolManager.jsp';  //点击确定后跳转到 院校信息页面
                            }
                        });


                    }else if(data.code == 1002){
                        layer.msg(data.msg);
                    }
                })
            });

            return false;
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function(){
            var data = form.val('example');
            alert(JSON.stringify(data));
        });

    });
</script>
</body>
</html>
